6.1 Configuring the CPU Mode
The head.S source file implements a global macro block named __HEAD, which instructs the linker mechanism to place all subsequent machine code within the dedicated .head.text section. The absolute baseline starting address of this section defines the definitive software entry point of the compiled Linux kernel—mapping explicitly to the address hosting the absolute first machine instruction to be executed by the kernel subsystem.
Stripping away architecture-unrelated macros designated for Thumb mode orchestration (where guest Linux kernels targeting Cortex-M microcontrollers execute within the Thumb state) and BE8 instruction re-ordering—both of which compile to empty tokens when the build configuration targets standard ARM execution engines—and omitting the extended multi-dimensional paging structures designed to support 40-bit physical address extensions (LPAE) supported under ARMv7-A profiles, this baseline assembly setup can be streamlined into the following functional loop:
.arm
__HEAD
ENTRY(stext)
safe_svcmode_maskall r9
mrc p15, 0, r9, c0, c0 @ Acquire CPU ID
bl __lookup_processor_type @ r5=procinfo r9=CPU ID
movs r10, r5 @ Invalid processor (r5=0)?
beq __error_p
adr r3, 2f
ldmia r3, {r4, r8}
sub r4, r3, r4 @ (PHYS_OFFSET - PAGE_OFFSET)
add r8, r8, r4 @ PHYS_OFFSET
bl __vet_atags
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT
bl __fixup_pv_table
#endif
bl __create_page_tables
ldr r13, =__mmap_switched @ Address to jump to after MMU has been enabled
badr lr, 1f @ Return (PIC) address
mov r8, r4 @ Set TTBR1 to swapper_pg_dir
ldr r12, [r10, #PROCINFO_INITFUNC]
add r12, r12, r10
ret r12
1: b __enable_mmu
ENDPROC(stext)
.ltorg
2: .long .
.long PAGE_OFFSET
Within this code block, the initial execution segment:
safe_svcmode_maskall r9
mrc p15, 0, r9, c0, c0
bl __lookup_processor_type
movs r10, r5
beq __error_p
guarantees that the processing CPU core is forced into Supervisor (SVC) mode, masks out all incoming asynchronous hardware interrupts, and identifies the explicit processor architecture type. The token safe_svcmode_maskall expands to a foundational macro sequence engineered to assign CPU processing modes and silence interrupt lines, passing register r9 as a scratch workspace register to the macro block. The programmatic workflow tracking this initial pipeline is structured as follows:
Figure 6-1 Supervisor (SVC) Mode Setup and Interrupt Masking Flowchart
The instruction mrc p15, 0, r9, c0, c0 issues a coprocessor transaction to pull the contents of register C0 from the CP15 coprocessor space, storing the data word inside scratch register r9. This internal CP15 C0 register serves as the core processor identification register housing the hardware CPU ID parameters.
The __lookup_processor_type subroutine searches the compiled architecture tables to resolve the exact silicon profile matching the active processor core. This tracking routine relies strictly on two system-wide positional constants: PAGE_OFFSET and PHYS_OFFSET. To parse the architectural functionality of these constants, it is necessary to establish the low-level concepts governing virtual addressing, physical addressing, kernel space, and user space (commonly referenced as kernel mode and user mode states). These fundamental networking and memory design paradigms are outlined below.
Depending on specific CPU microarchitectures and individual platform engineering layouts, the absolute starting boundaries and linear capacities of the volatile memory matrix vary widely. Because the Linux kernel provides native compatibility for an expansive taxonomy of disparate processor architectures and system topologies, the overwhelming majority of the codebase is written cleanly in the C programming language. Hardcoding absolute, literal memory coordinates within these portable software layers would make the codebase highly rigid and degrade its architectural scalability.
To abstract away these hardware variations, the Linux memory management framework acts as if all available system-wide address envelopes reside within a single uniform virtual boundary space extending from 0x00000000 to 0xFFFFFFFF; this abstract addressing layout defines the Virtual Address (VA) space. When system software initiates a memory access routine, the integrated Memory Management Unit (MMU) handles translation loops to map the abstract virtual coordinate to its true physical address layout on the silicon. Consequently, the CPU core executes instructions exclusively within the virtual address domain, whereas the underlying physical memory components consume sectors mapped inside the physical address domain.
The Linux kernel bifurcates this 4 GB virtual memory space (0x00000000 to 0xFFFFFFFF) into two mutually isolated runtime zones: user space and kernel space. User-space applications are restricted to executing within the boundaries of user space and are barred from cross-accessing or corrupting kernel memory; conversely, low-level core kernel routines execute within kernel space.
Mainline Linux implements exactly four split-ratio memory configurations to manage this layout. When the preprocessor build flag evaluates to CONFIG_VMSPLIT_1G, the kernel space envelope is mapped to span from 0x40000000 to 0xFFFFFFFF. Under the CONFIG_VMSPLIT_2G configuration profile, the kernel partition scales to occupy 0x80000000 to 0xFFFFFFFF. Toggling the switch to CONFIG_VMSPLIT_3G_OPT establishes a kernel memory allocation window spanning from 0xB0000000 to 0xFFFFFFFF. Finally, under the standard CONFIG_VMSPLIT_3G ratio allocation profile, the kernel space is assigned to occupy the top 1 GB segment extending from 0xC0000000 to 0xFFFFFFFF. Enforcing these build flag allocations is handled during the configuration phase, typically by appending explicit configuration directives (such as declaring CONFIG_VMSPLIT_1G=y) within the architecture board templates managed under the git/arch/arm/configs/*_defconfig path.
The constant parameter PHYS_OFFSET defines the absolute starting boundary address tracking the volatile memory array inside the hardware physical memory map. Conversely, PAGE_OFFSET registers the absolute starting virtual address allocating the base boundary of the protected kernel space. The hierarchical interface relationship linking virtual addresses, physical addresses, user space, kernel space, PHYS_OFFSET, and PAGE_OFFSET is illustrated in the structural diagram below:
Figure 6-2 Layout Mapping of the Linux Address Space
Having introduced the foundational paradigms of virtual and physical addressing layout configurations, this section evaluates the low-level ARM-assembly processor information discovery routine. The assembly implementation code for this subsystem is structured as follows:
__lookup_processor_type:
adr r3, __lookup_processor_type_data
ldmia r3, {r4 - r6}
sub r3, r3, r4 @ get offset between virt & phys
add r5, r5, r3 @ convert virt addresses to
add r6, r6, r3 @ physical address space
1: ldmia r5, {r3, r4} @ value, mask
and r4, r4, r9 @ mask wanted bits
teq r3, r4
beq 2f
add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)
cmp r5, r6
blo 1b
mov r5, #0 @ unknown processor
2: ret lr
ENDPROC(__lookup_processor_type)
.align 2
.type __lookup_processor_type_data, %object
__lookup_processor_type_data:
.long .
.long __proc_info_begin
.long __proc_info_end
.size __lookup_processor_type_data, . - __lookup_processor_type_data
Upon concluding the execution of this routine, register r9 preserves the hardware CPU ID signature, while register r5 registers the absolute physical destination address pointing to the matched processor metadata record. First, consider the trailing tracking directives block:
__lookup_processor_type_data:
.long .
.long __proc_info_begin
.long __proc_info_end
The assembly evaluation directive .long . writes the node's own compiled virtual execution address directly into the memory location mapped by the label __lookup_processor_type_data. The subsequent two contiguous storage assignments cache the virtual linking addresses bounding the symbols __proc_info_begin and __proc_info_end into the next two sequential memory slots.
The physical hardware metrics and processor descriptors tracking every silicon architecture natively supported by the compiled Linux kernel are clustered contiguously inside the memory region bounded by __proc_info_begin and __proc_info_end. These boundary markers are synthesized dynamically by the linker utility during compilation and are stored strictly as virtual addresses.
Because these data blocks are organized using virtual linking targets, and because the Memory Management Unit (MMU) has not yet been initialized at this point in the boot sequence, any programmatic attempt to read these processor configurations requires converting their virtual offsets to physical address coordinates.
The initial instruction of the subroutine calculates the precise physical address hosting the __lookup_processor_type_data pointer table (adding the Program Counter register value to the immediate relative byte offset of the label) and writes it into register r3. Using r3 as an absolute tracking base address, the ldmia command block loads the values of the compiled virtual anchors—representing ., __proc_info_begin, and __proc_info_end—into registers r4, r5, and r6 respectively.
The instruction sub r3, r3, r4 computes the precise translation delta separating the label's runtime physical position from its link-time virtual address. Leveraging this constant offset vector allows virtual memory descriptors to be converted directly to physical address paths (as shown in Figure 6-2). The execution commands add r5, r5, r3 and add r6, r6, r3 recalculate the virtual boundaries of __proc_info_begin and __proc_info_end into the active physical memory map.
The subsequent loop fetches individual processor blocks from memory and executes a mask-and-test evaluation against the hardware CPU ID signature cached inside register r9 (originally read from the CP15 coprocessor). If a valid record matching the signature is resolved, the loop terminates, and register r5 contains the physical address hosting that processor information structure. If the search pointer traverses the entire array from __proc_info_begin to __proc_info_end without finding a matching hardware signature, register r5 is cleared to zero, and the function returns. The sequential operational loop tracking this routine is mapped out below:
Figure 6-3 Processor Information Lookup Flowchart
U-BOOT passes platform parameters over to the guest Linux kernel via one of two legacy or modern interface protocols. On modern, Device-Tree-aware kernel compilation profiles, U-BOOT writes the absolute physical base address hosting the Flattened Device Tree binary blob into register r2. On legacy, non-Device-Tree targets, U-BOOT uses register r2 to pass the baseline pointer address referencing a structured list of parameters (atag list). Typically, U-BOOT places these environment lists or .dtb files within the initial 16 KB margin of physical RAM; the bootloader decompression routines and the early kernel instructions are fenced off to prevent overwriting this data window.
If the active kernel incorporates Device Tree capabilities, the validation engine interrogates the physical memory cell pointed to by register r2 to verify if it matches the Device Tree magic signature word. If the parsed cell matches the identifier signature, r2 contains a valid DTB container; otherwise, the payload is flagged as invalid. Under little-endian byte ordering models, this constant magic identifier matches the word 0xEDFE0DD0, whereas big-endian architectures store the signature as the big-endian word 0xD00DFEED.
Conversely, if the kernel is compiled without Device Tree capability, it interrogates the initial 4-byte tracking cell pointed to by register r2 to check for the signature values 0x00000005 (representing parameter size ATAG_CORE_SIZE) or 0x00000002 (representing an empty base parameter layout, ATAG_CORE_SIZE_EMPTY). If this initial integrity pass fails, the tracking location is discarded as an invalid parameter array. If the initial word is confirmed, the engine scans the next contiguous 8-byte data field to check for the explicit parameter key word ATAG_CORE (0x54410001). If this second validation loop matches the token signature, the memory reference inside r2 is registered as a fully authenticated, legal atag parameter array.
If the verification pass rejects the memory structure pointed to by r2 as an invalid DTB blob or unparseable atag array, register r2 is cleared to zero before control is returned to the calling function, informing downstream routines that the boot argument tracking reference is invalid.
The low-level assembly source code defining the __vet_atags validation routine is structured as follows:
__vet_atags:
tst r2, #0x3 @ aligned?
bne 1f
ldr r5, [r2, #0]
#ifdef CONFIG_OF_FLATTREE
ldr r6, =OF_DT_MAGIC @ is it a DTB?
cmp r5, r6
beq 2f
#endif
cmp r5, #ATAG_CORE_SIZE @ is first tag ATAG_CORE?
cmpne r5, #ATAG_CORE_SIZE_EMPTY
bne 1f
ldr r5, [r2, #4]
ldr r6, =ATAG_CORE
cmp r5, r6
bne 1f
2: ret lr @ atag/dtb pointer is ok
1: mov r2, #0
ret lr
ENDPROC(__vet_atags)
Because the syntactical composition of this assembly segment is linear, it does not require a detailed standalone execution flowchart.